package com.yx.backstage.converter;

import cn.hutool.core.date.DateUtil;
import com.yx.backstage.model.FileType;
import com.yx.backstage.model.param.FileTypeParam;
import com.yx.backstage.model.vo.FileTypeVo;
import com.yx.backstage.util.TimeFormat;

import java.util.ArrayList;
import java.util.List;

/**
 * @author YangXiong
 */
public class FileTypeConverter {
    public static List<FileTypeVo> handlerPageResult(List<FileType> records) {
        List<FileTypeVo> result = new ArrayList<>();
        records.forEach(record->{
            FileTypeVo vo = getFileTypeVo(record);
            result.add(vo);
        });
        return result;
    }

    public static FileTypeVo getFileTypeVo(FileType record) {
        FileTypeVo vo = new FileTypeVo();
        vo.setId(record.getId());
        vo.setEnable(record.getEnable());
        vo.setFileType(record.getFileType());
        vo.setKind(record.getKind());
        vo.setOperatorName(record.getOperatorName());
        vo.setName(record.getName());
        vo.setRemark(record.getRemark());
        String createTime = DateUtil.format(record.getCreateTime(), TimeFormat.TIME_FORMAT);
        vo.setCreateTime(createTime);
        String modifyTime = DateUtil.format(record.getModifyTime(), TimeFormat.TIME_FORMAT);
        vo.setModifyTime(modifyTime);
        return vo;
    }

    public static FileType getFileTypeDO(FileTypeParam param) {
        FileType fileType = new FileType();
        fileType.setId(param.getId());
        fileType.setKind(param.getKind());
        fileType.setFileType(param.getFileType());
        fileType.setRemark(param.getRemark());
        fileType.setEnable(param.getEnable());
        fileType.setName(param.getName());
        fileType.setOperatorName(param.getOperatorName());
        return fileType;
    }
}
